;'use strict';

$(function () {

    // https://www.w3schools.com/howto/howto_js_countdown.asp

    let reservationTime = Cookies.get('reservationTime');

    if (!reservationTime) {
        reservationTime = (new Date()).getTime() + 5 * 60 * 1000;
        Cookies.set(
            'reservationTime',
            reservationTime,
            {expires: new Date(reservationTime)}
        );
    }

    // Set the date we're counting down to
    var countDownDate = reservationTime;

    // Update the count down every 1 second
    var x = setInterval(function () {

        // Get todays date and time
        var now = new Date().getTime();

        // Find the distance between now and the count down date
        var distance = countDownDate - now;

        // Time calculations for days, hours, minutes and seconds
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);

        // Display the result in the element with id="demo"
        // document.getElementById("reservation-time").innerHTML = minutes + 'm ' + seconds + 's ';

        // If the count down is finished, write some text
        if (distance < 0) {
            clearInterval(x);
            document.getElementById("reservation-time").innerHTML = 'expired';
        }
    }, 1000);

});
